package com.jdh.fileUpload.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: RedissonConfig
 * @Author: jdh
 * @CreateTime: 2022-03-14
 * @Description:
 */
@Configuration
@ConditionalOnProperty(prefix = "autoconfigure", value = "isRedisson", matchIfMissing = false)
public class RedissonConfig {

//    @Autowired
//    private RedissonClient redissonClient;

    @Bean
    public RedissonClient getRedissonClient() {
        Config config = new Config();
        config.useSingleServer()
                .setAddress("redis://localhost:6379")
                .setPassword("123456")
                .setConnectionPoolSize(64)
                .setConnectionMinimumIdleSize(30) // 设置等待队列的最大容量
                .setIdleConnectionTimeout(10000) //设置全局锁等待超时时间为 60000 毫秒（即 60 秒）
                .setTimeout(3000);
        config.setCodec(new JsonJacksonCodec());

        // 创建 Redisson 客户端
        RedissonClient redissonClient = Redisson.create(config);

        return redissonClient;
    }

}
